package com.charles.springcloud.controller;

import com.charles.common.CommonResult;
import com.charles.springcloud.entity.Payment;
import com.charles.springcloud.service.PaymentService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;


/**
 * <p>
 * 支付表 前端控制器
 * </p>
 *
 * @author 风中灵劲草
 * @since 2021-07-18
 */
@RestController
@RequestMapping("/payment")
@Slf4j
public class PaymentController {

    @Value("${server.port}")
    private String serverPort;
    @Autowired
    private PaymentService paymentService;

    @PostMapping("/create")
    public CommonResult<String> create(@RequestBody Payment payment) {
        int result = paymentService.create(payment);
        if (result > 0)
            return CommonResult.success("创建成功");
        else
            return CommonResult.failed("创建失败");
    }

    @GetMapping("/getPayment/{id}")
    public CommonResult<Payment> getPaymentById(@PathVariable("id") Long id) {
        Payment payment = paymentService.getPaymentById(id);
        return CommonResult.success(payment);
    }

    @GetMapping("/lb")
    public String getPaymentLB(){
        return serverPort;
    }
}
